
require('./index.css');

window.onload = function() {
  // 开启全屏
  function openFullScreen(e) {
    if (e.requestFullscreen) {
      e.requestFullscreen();
    }
    if (e.mozRequestFullScreen) {
      e.mozRequestFullScreen();
    }
    if (e.msRequestFullscreen) {
      e.msRequestFullscreen();
    }
    if (e.webkitRequestFullscreen) {
      e.webkitRequestFullscreen();
    }
  }
  
  // 退出全屏
  function exitFullscreen(e) {
    if (e.exitFullscreen) {
      e.exitFullscreen();
    }
    if(document.mozCancelFullScreen){
      document.mozCancelFullScreen();
    }
    if(document.msExitFullscreen){
      document.msExiFullscreen();
    }
    if(document.webkitCancelFullScreen){
      document.webkitCancelFullScreen();
    }
  }
  
  // 成功的监听事件
  function handleFullScreen() {
    // document.getElementById('myDiv').webkitRequestFullscreen();
    // document.documentElement.webkitRequestFullScreen();
    openFullScreen(document.documentElement);
  }
  document.getElementsByTagName('button')[0].onclick = function() {
    handleFullScreen();
  }
  // 成功的监听事件（chrome）
  document.addEventListener("webkitfullscreenchange", function( event ) {
    console.log('success');
    console.log(document.fullscreenElement); // 返回打开全屏的监听元素
  });

  // 失败的监听事件（chrome）
  document.addEventListener("webkitfullscreenerror", function( event ) {
    console.log('error');
  });
}